package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxClass;
import com.ruoyi.system.service.IRxClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运营商分类Controller
 *
 * @author hjf
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/order/class")
public class RxClassController extends BaseController {
    @Autowired
    private IRxClassService rxClassService;

    /**
     * 查询运营商分类列表
     */
    @PreAuthorize("@ss.hasPermi('order:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxClass rxClass) {
        startPage();
        List<RxClass> list = rxClassService.selectRxClassList(rxClass);
        return getDataTable(list);
    }


    @GetMapping("/simpleList")
    public AjaxResult simpleList(RxClass rxClass) {
        List<RxClass> list = rxClassService.selectRxClassList(rxClass);
        return AjaxResult.success(list);
    }


    /**
     * 导出运营商分类列表
     */
    @PreAuthorize("@ss.hasPermi('order:class:export')")
    //@Log(title = "运营商分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxClass rxClass) {
        List<RxClass> list = rxClassService.selectRxClassList(rxClass);
        ExcelUtil<RxClass> util = new ExcelUtil<RxClass>(RxClass.class);
        util.exportExcel(response, list, "运营商分类数据");
    }

    /**
     * 获取运营商分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:class:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxClassService.selectRxClassById(id));
    }

    /**
     * 新增运营商分类
     */
    @PreAuthorize("@ss.hasPermi('order:class:add')")
    //@Log(title = "运营商分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxClass rxClass) {
        return toAjax(rxClassService.insertRxClass(rxClass));
    }

    /**
     * 修改运营商分类
     */
    @PreAuthorize("@ss.hasPermi('order:class:edit')")
    //@Log(title = "运营商分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxClass rxClass) {
        return toAjax(rxClassService.updateRxClass(rxClass));
    }

    /**
     * 删除运营商分类
     */
    @PreAuthorize("@ss.hasPermi('order:class:remove')")
    //@Log(title = "运营商分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxClassService.deleteRxClassByIds(ids));
    }
}
